package com.booth.base.model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
/***
 * 模块具有的链接
 * @TypeName：ModuleActions
 * @description：
 * @author：Administrator
 */
public class ModuleActions extends Model<ModuleActions>
{
	private static final long 		serialVersionUID	= 1L;
	public static final ModuleActions	dao			= new ModuleActions();
	/***
	 * 根据模块id获取该模块的链接
	 * @param id：模块id
	 * @return
	 */
	public static List<ModuleActions> findByModulesId( int id )
	{
		return(dao.find( "SELECT * FROM module_actions WHERE id=?", new Object[] { Integer.valueOf( id ) } ) );
	}
	/***
	 * 根据模块id删除模块的链接
	 * @param id：模块id
	 */
	public static void deleteByModuleId( int id )
	{
		Db.update( "DELETE FROM module_actions WHERE id=?", new Object[] { Integer.valueOf( id ) } );
	}
	/***
	 * 根据组具有的模块获取模块的链接
	 * @param gid：组id
	 * @return
	 */
	public static List<String> findByGroupId( int gid )
	{
		List		arr	= new ArrayList();
		List		lst	= dao.find( "SELECT distinct action_url FROM module_actions WHERE id in (SELECT modules_id FROM groups_modules WHERE group_id=?)", new Object[] { Integer.valueOf( gid ) } );
		Iterator	it	= lst.iterator();
		while ( it.hasNext() )
		{
			arr.add( ( (ModuleActions) it.next() ).getStr( "action_url" ) );
		}
		return(arr);
	}
}